﻿@using ServiceStack.Html
@inherits UiComponentBase

<ErrorSummary ExplicitStatus=@(Api?.Error) Except=@VisibleFields />
<div class="flex flex-1 flex-col justify-between">
    <div class="divide-y divide-gray-200 px-4 sm:px-6">
        <div class="space-y-6 pt-6 pb-5">

            <fieldset class="grid grid-cols-12 gap-6">
                @foreach (var f in FormLayout.OrEmpty())
                {
                    var propType = MetadataType.Properties.FirstOrDefault(x => x.Name == f.Id);
                    var dataModelProp = DataModelType.Property(f.Id);
                    if (f.Ignore == true || !BlazorUtils.SupportsProperty(propType))
                    {
                        continue;
                    }

                    <div class=@CssUtils.ClassNames(
                         f.Css?.Field ?? (f.Type == Input.Types.Textarea 
                            ? "col-span-12"
                            : "col-span-12 xl:col-span-6" + (f.Type == Input.Types.Checkbox ? " flex items-center" : "")),
                            f.Type == Input.Types.Hidden ? "hidden" : "") style="width:100%">

                         @if (dataModelProp?.Ref != null && f.Type != Input.Types.File)
                         {
                            <LookupInput MetadataType=@DataModelType Input=@f Model=@ModelDictionary Status=@Api?.Error />
                         }
                         else
                         {
                            <DynamicInput Input=@f Model=@ModelDictionary Status=@Api?.Error />
                         }
                    </div>
                }
            </fieldset>

        </div>
    </div>
</div>
